#!/bin/bash
#centos76 init  + docker-ce ntp 
#yum update -y
#yum install wget -y
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://192.168.50.211/repos/base.repos
sudo curl -o /etc/yum.repos.d/epel.repo http://192.168.50.211/repos/epel.repos
sudo curl -o /etc/yum.repos.d/elrepo.repo http://192.168.50.211/repos/elrepo.repos
sudo yum clean all
sudo yum makecache
sudo yum update -y
sudo yum install telnet net-tools ntp epel-release container-selinux -y
sudo systemctl enable ntpd
sudo systemctl start ntpd
sudo ntpdate cn.pool.ntp.org
sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
#sudo yum-config-manager \
#  --add-repo \
#  https://download.docker.com/linux/centos/docker-ce.repo
sudo curl -o /etc/yum.repos.d/docker-ce.repo http://192.168.50.211/repos/docker-ce.repos
sudo yum install -y docker-ce
sudo systemctl enable docker.service
sudo mkdir -p /data/docker/data-root
sudo mkdir -p /etc/docker
if [ ! -f "/etc/docker/daemon.json" ]; then
	sudo touch /etc/docker/daemon.json
	sudo chmod 646 /etc/docker/daemon.json
fi
sudo cat > /etc/docker/daemon.json <<EOF
{
  "data-root": "/data/docker/data-root",
  "registry-mirrors" : [
    "https://6zy5kcio.mirror.aliyuncs.com"
  ]
}
EOF
sudo systemctl enable docker && sudo systemctl restart docker
sudo systemctl restart firewalld 
sudo firewall-cmd \
  --add-port=80/tcp \
  --add-port=443/tcp \
  --add-port=2379/tcp \
  --add-port=2380/tcp \
  --add-port=8472/udp \
  --add-port=9099/tcp \
  --add-port=9796/tcp \
  --add-port=10250/tcp \
  --add-port=10254/tcp \
  --add-port=6443/tcp \
  --add-port=49622/tcp \  
  --add-port=30000-40000/tcp \
  --add-port=30000-40000/udp \
  --add-port=500-4500/udp \
  --permanent
sudo firewall-cmd --reload
if [ ! -f "/etc/sysctl.d/k8s.conf" ]; then
	sudo touch /etc/sysctl.d/k8s.conf
	sudo chmod 646 /etc/sysctl.d/k8s.conf
fi
sudo cat > /etc/sysctl.d/k8s.conf << EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
vm.swappiness=0
vm.max_map_count=655360 
EOF

sudo sysctl -p /etc/sysctl.d/k8s.conf